var t = getApp();

Page({
    data: {
        info: {},
        isShowPage: !1
    },
    onLoad: function(t) {
        t.salesId && t.NRLevelId ? this.gotoOrder() : (this.setData({
            isShowPage: !0
        }), this.getData());
    },
    getData: function() {
        var o = this, e = t.getNetAddresss("plugin.new-retail.frontend.index.getSalesRecord");
        t._postNetWork({
            url: e,
            data: {
                id: this.options.id
            },
            success: function(e) {
                var i = e.data;
                if (1 == i.result) {
                    if (i.data.remaining_time) {
                        var n = t.getTimeDifference(i.data.remaining_time);
                        o.setData({
                            remaining_time: n
                        });
                    }
                    o.setData({
                        info: i.data
                    });
                } else wx.showToast({
                    title: i.msg,
                    duration: 1e3,
                    icon: "none"
                });
            },
            fail: function(t) {
                wx.hideLoading(), console.log(t.msg);
            }
        });
    },
    gotoOrder: function() {
        wx.navigateTo({
            url: "/packageD/buy/myOrder_v2/myOrder_v2?tag=newRetail&goodsId=0&optionsId=0&total=0&retailState=5&NRLevelId=" + this.options.NRLevelId + "&sales_id=" + this.options.salesId
        });
    },
    ImgPreview: function() {
        var t = this.data.info.url;
        wx.previewImage({
            current: t,
            urls: [ t ]
        });
    },
    saveImg: function() {
        wx.getSetting({
            success: function(t) {
                t.authSetting["scope.writePhotosAlbum"] || wx.authorize({
                    scope: "scope.writePhotosAlbum",
                    success: function() {
                        console.log("授权成功");
                    }
                });
            }
        });
        var t = this.data.info.small_url;
        wx.downloadFile({
            url: t,
            success: function(t) {
                console.log(t), wx.saveImageToPhotosAlbum({
                    filePath: t.tempFilePath,
                    success: function(t) {
                        wx.showToast({
                            title: "保存成功",
                            icon: "none",
                            duration: 2e3
                        });
                    },
                    fail: function(t) {
                        console.log(t), "saveImageToPhotosAlbum:fail auth deny" === t.errMsg && (console.log("当初用户拒绝，再次发起授权"), 
                        wx.openSetting({
                            success: function(t) {
                                t.authSetting["scope.writePhotosAlbum"] ? wx.showToast({
                                    icon: "none",
                                    title: "获取权限成功,再次长按保存图片",
                                    duration: 1500
                                }) : wx.showToast({
                                    icon: "none",
                                    title: "获取权限失败,保存图片需要用户授权",
                                    duration: 1500
                                });
                            }
                        }));
                    },
                    complete: function(t) {
                        console.log(t);
                    }
                });
            }
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function(t) {
        var o = wx.getStorageSync("yz_uid"), e = "";
        return o && (e = o), {
            title: this.data.info.goods[0].goods_title,
            imageUrl: this.data.info.goods[0].goods_thumb,
            path: "/packageD/buy/myOrder_v2/myOrder_v2?tag=newRetail&goodsId=0&optionsId=0&total=0&retailState=5&NRLevelId=" + this.data.info.level_id + "&sales_id=" + this.options.id + "&mid=" + e
        };
    }
});